/*
 * @lc app=leetcode.cn id=6 lang=cpp
 *
 * [6] Z 字形变换
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
// @lc code=start
class Solution {
public:
    string convert(string s, int numRows) {
        int n = s.size();
        vector<string> arr (1010);
        if(n < numRows || numRows == 1) {
            return s;
        }
        int flag=-1;
        int cnt=0;
        for(int i = 0;i < n; ++i){
            arr[cnt] += s[i];
            if(cnt == numRows-1 || cnt == 0) {
                flag = -flag;
            }
            cnt += flag;
        }
        string ret = "";
        for(int i = 0;i < arr.size(); ++i) {
            ret += arr[i];
        }
        return ret;
    }
};
// @lc code=end

